home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Lib / include / AUTO.h next >
Encoding:
C/C++ Source or Header  |  1994-06-15  |  6.0 KB  |  218 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     MODULE
  5.     AUTO.h
  6.  
  7.     DESCRIPTION
  8.     Header file for use with "compiler
  9.     independent autoinit/autoexit routines"
  10.  
  11.     USAGE
  12.  
  13.       METHOD 1
  14.  
  15.     that method does (hopefully) not use any compiler
  16.     depencies, to enable auto-initialisation;
  17.     all You need is an ANSI-Compiler, a Make-Utility
  18.     and a Grep-Utility (better [f]lex)
  19.  
  20.       * call "AUTO_Init();" at the beginning of main()
  21.  
  22.       * each function, that should use auto_initialisation
  23.     must get a line "AUTOINIT(<functionname>)"
  24.     somewhere is your *.c module; (the same for
  25.     auto-atexit and AUTOEXIT(...)).
  26.     Be aware, that that line will be used o create
  27.     a call to your function, so don't put any Garbage
  28.     behind it.
  29.     while declaring that line inside a comment,
  30.     You need not include any additional file;
  31.     while declaring that line in C-code, you have to
  32.     #include "AUTO.h" or to #define AUTO(IN|EX)IT(x)
  33.     to nothing;
  34.  
  35.       * put some additional dependencies into your Makefile:
  36.  
  37.     M> AUTO.o : AUTO.c _AUTO_enex.h
  38.     M>
  39.     M> _AUTO_enex.h : $(C_sources)
  40.     M>       egrep -h -e "^[ ]*AUTO(IN|EX)IT\([ ]*[A-Za-z0-9_]+[ ]*\)" $(C_sources) > $*.h
  41.     M>
  42.  
  43.     and add AUTO.c to Your $(C_sources).
  44.  
  45.  
  46.       METHOD 2
  47.  
  48.     that Method is designed to support the Compiler-builtin
  49.     Auto-initialisation features, like used by DICE or SAS/C,
  50.     but if not using one of those compilers,
  51.  
  52.       * call "AUTO_Init();" at the beginning of main()
  53.     this is done for future support of GNU/C, which to my
  54.     knowledge has no autoinit support
  55.  
  56.       * surround the definition of each auto??it-function
  57.     with MK_AUTO??IT(), where MK_AUTO..IT must be the 1st
  58.     word of a line. Wanna say, write
  59.     C> MK_AUTOINIT( my_init ) { ...
  60.     where DICE expects
  61.     C> __autoinit void my_init(void) { ...
  62.     or SAS/C expects
  63.     C> void STI_my_init(void) { ...
  64.  
  65.       * as long as Your compiler is supporting auto??it-features,
  66.     there is currently no need to do any addes to the Makefile;
  67.     but it should be done anyway, since the program might also
  68.     compiled with another system ...
  69.  
  70.       * there might occur problems, if the compiler expects autoinit
  71.     functions to return errorcodes or successvalues
  72.  
  73.     REQUIREMENTS
  74.  
  75.       METHOD 1
  76.  
  77.       * You must use egrep or something like that to extract
  78.     the autoinit-funktions from Your sources;
  79.     the "-h" options seems not to be available for each version
  80.     of egrep over there (#$&%^$& HPUX), so there might be some
  81.     other solution neccessary.
  82.  
  83.     e.g. it should be possible using sedwith something like:
  84.     M>  sed -n "s/^ *AUTO_..IT( *[A-Za-z0-9_]* *)/p" >
  85.     but I was never forced to use something like that,
  86.     so it is untested.
  87.  
  88.       METHOD 2
  89.  
  90.       * while using SAS/C or DICE there is no other tool necessary
  91.     when using GNU/C a parser like shown below is necessary,
  92.     so lex might be used to create it...
  93.  
  94.     the parser might be a lex-pgm like the following
  95.     L> WS    [ \n\t]
  96.     L> DLM    [A-Za-z_][A-Za-z_0-9]*
  97.     L> %%
  98.     L> ^{WS}*(MK_)?AUTO(IN|EX)IT{WS}*"("{WS}*{DLM}{WS}*")" printf("%s;",yytext);
  99.     L> .                          ;
  100.     to create the scanner just type
  101.     %> lex lex.l
  102.     %> gcc lex.yy.c -ll
  103.     to get it work in a Makefile
  104.     M> _AUTO_enex.h : $(OWN_C_SRCS)
  105.     M>       cat $(OWN_C_SRCS) | a.out > _AUTO_ENEX.h
  106.  
  107.  
  108.     NOTES
  109.     please have a look into AUTO.c, too
  110.  
  111.     Please note the two introduced methods are to be used mutally
  112.     exclusive, i.e. using "AUTO_??IT(func_x)" and defining
  113.     "MK_AUTO??IT(func_x){...}" causes func_x be called twice,
  114.     which might lead into undefined situations ...
  115.  
  116.     if Your compiler is capable of an own technique for
  117.     auto-init/exit declarations, there is no need for this
  118.     module, but porting might be a little bit more easy
  119.     while using it ;-)
  120.  
  121.     the following compilers have own techniques
  122.     (the list is surely incomplete)
  123.     SAS-C v6.*  (Platform AMIGA)
  124.     DICE 2.0*r  (Platform AMIGA)
  125.  
  126.     HISTORY
  127.     07-12-93 b_noll created
  128.     15-06-94 b_noll added (void) into MK_AUTO??IT
  129.  
  130. ******************************************************************************/
  131.  
  132. #ifndef AUTO_H
  133. #define AUTO_H
  134.  
  135. /**************************************
  136.         Includes
  137. **************************************/
  138.  
  139. /* none */
  140.  
  141. /**************************************
  142.         Global Variables
  143. **************************************/
  144.  
  145. /* none */
  146.  
  147. /**************************************
  148.         Defines & Structures
  149. **************************************/
  150.  
  151. /* ---- this is not necessary, if we are only using the named methods */
  152. #ifndef _DCC
  153. #define __autoinit
  154. #define __autoexit
  155. #endif
  156.  
  157. /**************************************
  158.         Macros
  159. **************************************/
  160.  
  161. /* ---- Method # 1 - compiler independent   */
  162. /*    the work is done in AUTO.c and with */
  163. /*    a scanner                */
  164.  
  165. #define AUTOINIT(x)
  166. #define AUTOEXIT(x)
  167.  
  168.  
  169. /* ---- Method # 2 - use compiler techniques, if possible */
  170.  
  171. #if defined(_DCC)
  172. #   define SUPPORT_AUTO 1
  173. #   define    MK_AUTOINIT(func_name) __autoinit void func_name (void)
  174. #   define    MK_AUTOEXIT(func_name) __autoexit void func_name (void)
  175. #endif
  176.  
  177. #if defined(__SASC)
  178. #   define SUPPORT_AUTO 1
  179. #   define    MK_AUTOINIT(func_name) void _STI_ ## func_name (void)
  180. #   define    MK_AUTOEXIT(func_name) void _STD_ ## func_name (void)
  181. #endif
  182.  
  183.  
  184. /* ---- other compilers which support auto-entry/exit */
  185. /*    features should be treated here           */
  186.  
  187.  
  188.  
  189. /* ---- ok, no compiler support; then we also need a */
  190. /*    scanner here to invoke these functionality   */
  191. #ifndef    SUPPORT_AUTO
  192. #   define SUPPORT_AUTO 0
  193. #   define    MK_AUTOINIT(func_name) void func_name (void)
  194. #   define    MK_AUTOEXIT(func_name) void func_name (void)
  195. #endif
  196.  
  197. /**************************************
  198.         Prototypes
  199. **************************************/
  200.  
  201. /* ---- that function is recommended to be called at the beginning of     */
  202. /*    main(); it is used for method # 1 in any case, and for method 2, */
  203. /*    if the used compiler is not known to support own auto-entry/exit */
  204. /*    techniques                             */
  205. #if SUPPORT_AUTO
  206. #   define  AUTO_Init()
  207. #else
  208. extern void AUTO_Init(void);
  209. #endif
  210.  
  211.  
  212. #endif /* AUTO_H */
  213.  
  214. /******************************************************************************
  215. *****  END AUTO.h
  216. ******************************************************************************/
  217.  
  218.